﻿using System;
using System.Collections.Generic;

using DesignPattern.AbsFactory;
using DesignPattern.AbsFactory.Product;
using DesignPattern.AbsFactory.Product.Acer;

namespace DesignPattern.Single
{
    /// <summary>
    /// 电脑工厂，使用反射创建工厂对象
    /// </summary>
    public sealed class Factory 
    {
        /// <summary>
        /// 静态只读程序集名称
        /// </summary>
        private readonly static string assemblySetting = "DesignPattern";//System.Configuration.ConfigurationManager.AppSettings["AssemblySetting"];
        /// <summary>
        /// 静态只读工厂实例名称
        /// </summary>
        private readonly static string factorySetting = "AbsFactory.AcerFactory";//System.Configuration.ConfigurationManager.AppSettings["FactorySetting"];
        /// <summary>
        /// 静态工厂实例
        /// </summary>
        private static AbsComputerFactory instance ;

        #region 构造

        private Factory()
        {

        }

        static Factory()
        { 
            
        }

        #endregion
        /// <summary>
        /// 工厂实例
        /// </summary>
        public static AbsComputerFactory GetInstance
        {
            get
            {
                if (instance == null )
                {
                    instance = Create.Instance;
                }
                return instance;
            }        
        }

        class Create
        {
            private Create()
            {

            }
            internal static AbsComputerFactory Instance
            {
                get
                {
                    return System.Reflection.Assembly.Load(assemblySetting).CreateInstance(factorySetting) as AbsComputerFactory;
                }
            }
        }

    }
}
